package com.mc.web.controller.fil;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mc.common.annotation.Log;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.enums.BusinessType;
import com.mc.fil.domain.FilHarvestRecords;
import com.mc.fil.service.IFilHarvestRecordsService;
import com.mc.common.utils.poi.ExcelUtil;
import com.mc.common.core.page.TableDataInfo;

/**
 * 采种田采收记录Controller
 *
 * @author mc
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/fil/harvest")
public class FilHarvestRecordsController extends BaseController
{
    @Autowired
    private IFilHarvestRecordsService filHarvestRecordsService;

    /**
     * 查询采种田采收记录列表
     */
    @PreAuthorize("@ss.hasPermi('fil:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilHarvestRecords filHarvestRecords)
    {
        startPage();
        List<FilHarvestRecords> list = filHarvestRecordsService.selectFilHarvestRecordsList(filHarvestRecords);
        return getDataTable(list);
    }

    /**
     * 导出采种田采收记录列表
     */
    @PreAuthorize("@ss.hasPermi('fil:records:export')")
    @Log(title = "采种田采收记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilHarvestRecords filHarvestRecords)
    {
        List<FilHarvestRecords> list = filHarvestRecordsService.selectFilHarvestRecordsList(filHarvestRecords);
        ExcelUtil<FilHarvestRecords> util = new ExcelUtil<FilHarvestRecords>(FilHarvestRecords.class);
        return util.exportExcel(list, "records");
    }

    /**
     * 获取采种田采收记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('fil:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(filHarvestRecordsService.selectFilHarvestRecordsById(id));
    }

    /**
     * 新增采种田采收记录
     */
    @PreAuthorize("@ss.hasPermi('fil:records:add')")
    @Log(title = "采种田采收记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilHarvestRecords filHarvestRecords)
    {
        return toAjax(filHarvestRecordsService.insertFilHarvestRecords(filHarvestRecords));
    }
}